/*jslint browser: true, devel: true, bitwise: true, white: true, plusplus: true, forin:true */
/*global $:true, define:true, describe:true,it:true,expect:true,beforeEach:true */

define(['Utility/Data/LinkedList'], function(LinkedList) {
	"use strict";

describe('LinkedList Tests',function() {
	var list;
		
	beforeEach(function() {
		list = new LinkedList();
	});
		
	it('Create list',function() {
		expect(list.length).toBe(0);
		expect(list.head).toBe(undefined);
		expect(list.tail).toBe(undefined);
	});
		
	it('isEmpty()',function() {
		expect(list.isEmpty()).toBe(true);
	});
	
	it('append() 1 node',function() {
		var node = list.append(1);
			
		expect(list.length).toBe(1);
		expect(list.isEmpty()).toBe(false);
			
		expect(list.head).toBe(node);
		expect(list.tail).toBe(node);
			
		expect(node.data).toBe(1);
		expect(node.prev).toBeUndefined();
		expect(node.next).toBeUndefined();
			
	});
		
	it('append() 2 nodes',function() {
		var 
			node1 = list.append(1),
			node2 = list.append(2);
			
		expect(list.length).toBe(2);
			
		expect(list.head).toBe(node1);
		expect(list.tail).toBe(node2);
			
		expect(node1.data).toBe(1);
		expect(node1.prev).toBeUndefined();
		expect(node1.next).toBe(node2);
		
		expect(node2.data).toBe(2);
		expect(node2.prev).toBe(node1);
		expect(node2.next).toBeUndefined();
			
	});
		
	it('append() 3 nodes',function() {
		var 
			node1 = list.append(1),
			node2 = list.append(2),
			node3 = list.append(3);
			
		expect(list.length).toBe(3);
			
		expect(list.head).toBe(node1);
		expect(list.tail).toBe(node3);
			
		expect(node1.data).toBe(1);
		expect(node1.prev).toBeUndefined();
		expect(node1.next).toBe(node2);
			
		expect(node2.data).toBe(2);
		expect(node2.prev).toBe(node1);
		expect(node2.next).toBe(node3);
			
		expect(node3.data).toBe(3);
		expect(node3.prev).toBe(node2);
		expect(node3.next).toBeUndefined();
			
	});
	
	it('insertBefore(),list with one node, adding next node before',function() {
		var 
			node1 = list.append(1),
			node2 = list.insertBefore(2,node1);
			
		expect(list.length).toBe(2);
			
		expect(list.head).toBe(node2);
		expect(list.tail).toBe(node1);
			
		expect(node1.data).toBe(1);
		expect(node1.prev).toBe(node2);
		expect(node1.next).toBeUndefined();
			
		expect(node2.data).toBe(2);
		expect(node2.prev).toBeUndefined();
		expect(node2.next).toBe(node1);
			
	});
	
	it('insertAfter() list with one node, adding next node after',function() {
		var 
			node1 = list.append(1),
			node2 = list.insertAfter(2,node1);
			
		expect(list.length).toBe(2);
			
		expect(list.head).toBe(node1);
		expect(list.tail).toBe(node2);
			
		expect(node1.data).toBe(1);
		expect(node1.prev).toBeUndefined();
		expect(node1.next).toBe(node2);
			
		expect(node2.data).toBe(2);
		expect(node2.prev).toBe(node1);
		expect(node2.next).toBeUndefined();
			
	});
	
	it('remove() from 1 element list',function() {
		var node1 = list.append(1);
		
		list.remove(node1);
		expect(list.length).toBe(0);
		
		expect(list.head).toBeUndefined();
		expect(list.tail).toBeUndefined();
	});
	
	it('remove() from 2 elements list',function() {
		var 
			node1 = list.append(1),
			node2 = list.append(2);
		
		list.remove(node1);
		expect(list.length).toBe(1);
		
		expect(list.head).toBe(node2);
		expect(list.tail).toBe(node2);
		
		node1 = list.append(3);
		list.remove(node1);
		
		expect(list.head).toBe(node2);
		expect(list.tail).toBe(node2);
	});
	
	it('iterator() iterate 10 elements list',function() {
		var i, it,data;
		for (i = 0;i < 10; ++i) {
			list.append(i);
		}
		
		it = list.iterator();
		expect(it.Current).toBe(list.head);
		i = 0;
		while((data = it.next()) !== undefined) {
			expect(data).toBe(i);
			++i;
		}
		
		it = list.iterator();
		i = 0;
		while(it.hasNext()) {
			expect(it.next()).toBe(i);
			++i;
		}
	});
	
	it('reverseIterator() iterate 10 elements list from end',function() {
		var i, it,data;
		for (i = 0;i < 10; ++i) {
			list.append(i);
		}
		
		it = list.reverseIterator();
		expect(it.Current).toBe(list.tail);
		i = 9;
		while((data = it.prev()) !== undefined) {
			expect(data).toBe(i);
			--i;
		}
		
		it = list.reverseIterator();
		i = 9;
		while(it.hasPrev()) {
			expect(it.prev()).toBe(i);
			--i;
		}
	});
	/*
	it('pushFront first node',function() {
		var node = list.pushFront(1);
			
		expect(list.getSize()).toBe(1);
		expect(list.isEmpty()).toBe(false);
			
		expect(list.Head).toBe(node);
		expect(list.Tail).toBeUndefined();
			
		expect(node.data).toBe(1);
		expect(node.prev).toBeUndefined();
		expect(node.next).toBeUndefined();
			
	});
		
	it('pushFront two nodes',function() {
		var 
			node1 = list.pushFront(1),
			node2 = list.pushFront(2);
			
		expect(list.getSize()).toBe(2);
			
		expect(list.Tail).toBe(node1);
		expect(list.Head).toBe(node2);
			
		expect(node1.data).toBe(1);
		expect(node1.prev).toBe(node2);
		expect(node1.next).toBeUndefined();
			
		expect(node2.data).toBe(2);
		expect(node2.prev).toBeUndefined();
		expect(node2.next).toBe(node1);
			
	});
		
	it('pushFront there nodes',function() {
		var 
			node1 = list.pushFront(1),
			node2 = list.pushFront(2),
			node3 = list.pushFront(3);
			
		expect(list.getSize()).toBe(3);
			
		expect(list.Head).toBe(node3);
		expect(list.Tail).toBe(node1);
			
		expect(node1.data).toBe(1);
		expect(node1.prev).toBe(node2);
		expect(node1.next).toBeUndefined();
			
		expect(node2.data).toBe(2);
		expect(node2.prev).toBe(node3);
		expect(node2.next).toBe(node1);
			
		expect(node3.data).toBe(3);
		expect(node3.prev).toBeUndefined();
		expect(node3.next).toBe(node2);
			
	});
	
	it('popBack from empty list',function() {
		expect(list.popBack()).toBeUndefined();
		expect(list.getSize()).toBe(0);	
	});
	
	it('popBack from one node list',function() {
		var node = list.pushBack(1);
		
		expect(list.popBack()).toBe(1);
		expect(list.Head).toBeUndefined();
		expect(list.Tail).toBeUndefined();
		expect(list.getSize()).toBe(0);	
	});
	
	it('popBack from two node list',function() {
		var 
			node1 = list.pushBack(1),
			node2 = list.pushBack(2);
		
		expect(list.popBack()).toBe(2);
		expect(list.getSize()).toBe(1);	
		expect(list.Head).toBe(node1);
		expect(list.Head).toBe(list.Tail);
		expect(list.Tail).toBeUndefined();
		
	});
	
	it('popFront from empty list',function() {
		expect(list.popBack()).toBeUndefined();
		expect(list.getSize()).toBe(0);	
	});
	
	it('popFront from one node list',function() {
		var node = list.pushFront(1);
		
		expect(list.popFront()).toBe(1);
		expect(list.getSize()).toBe(0);	
	});*/
});

});
